﻿using System.Collections.Generic;
using FocalSpec.FsApiNet.Model;

namespace FocalSpec.GuiExample.Model.Camera
{

    public class Profile
    {
        public IList<FsApi.Point> Points { get; set; }

        public FsApi.Header Header { get; set; }

        public float AverageIntensity { get; set; }

        public int LayerId { get; set; }

        public Profile(IList<FsApi.Point> points, FsApi.Header header)
        {
            Points = points;
            Header = header;
            AverageIntensity = 0.0f;
            LayerId = -1;
        }
        public Profile(Profile profile)
        {
            Points = profile.Points;
            Header = profile.Header;
            AverageIntensity = profile.AverageIntensity;
            LayerId = profile.LayerId;
        }

        public Profile(int layerId, float[] zValues, float[] intensityValues, int lineLength,double xStep, FsApi.Header header)
        {
            LayerId = layerId;
            Points = new List<FsApi.Point>();
            float no_meas = FsApi.NoMeasurement - 1;
            float average = 0;
            for (int i = 0; i < lineLength; i++)
            {
                //if (zValues[i] > no_meas)
                //{
                //    continue;
                //}

                var p = new FsApi.Point()
                {
                    Y = zValues[i],
                    X = (float)(i * xStep),
                    Intensity = intensityValues[i]
                };
                average += intensityValues[i];
                Points.Add(p);
            }

            Header = header;
            if (Points.Count > 0)
            {
                AverageIntensity = average / Points.Count;
            }
        }
    }
}
